package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.domain.UmsResourceCategory;
import com.itheima.mapper.UmsResourceCategoryMapper;
import com.itheima.mapper.UmsResourceMapper;
import com.itheima.service.db.UmsResourceCategoryService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author ZhuHongKai
 * @version 1.0
 * @ClassName UmsResourceServiceImpl
 * @date 2022/11/13 1:48
 */
@DubboService
public class UmsResourceCategoryServiceImpl implements UmsResourceCategoryService {

    @Autowired
    UmsResourceMapper umsResourceMapper;

    @Autowired
    UmsResourceCategoryMapper umsResourceCategoryMapper;

    @Override
    public List<UmsResourceCategory> listAll() {
        List<UmsResourceCategory> umsResources = umsResourceCategoryMapper.selectList(null);
        return umsResources;
    }

    /**
     * 修改后台资源分类
     * @param id
     * @param umsResourceCategory
     */
    @Override
    public void resourceCategoryUpdate(Long id, UmsResourceCategory umsResourceCategory) {
        umsResourceCategory.setId(id);
        umsResourceCategoryMapper.updateById(umsResourceCategory);
    }

    /**
     * 根据ID删除后台资源
     * @param id
     */
    @Override
    public void delete(Long id) {
        LambdaQueryWrapper<UmsResourceCategory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UmsResourceCategory::getId,id);
        umsResourceCategoryMapper.delete(queryWrapper);
    }

    @Override
    public void save(UmsResourceCategory umsResourceCategory) {
        umsResourceCategory.setCreateTime(LocalDateTime.now());
        umsResourceCategoryMapper.insert(umsResourceCategory);
    }
}
